// 云函数入口文件
const cloud = require('wx-server-sdk')
const axios = require('axios')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
})

// 云函数入口函数
exports.main = async (event, context) => {
  await axios.get('https://upotato-prod-1561807-1309083682.ap-shanghai.run.tcloudbase.com/api/timer', {timeout: 5000})
    .then((response) => {
      console.log(response.data)
      return response.data
    })
    .catch(async (error) => {
      console.error(error);
      const result = await cloud.openapi.cloudbase.addDelayedFunctionTask({
        "env": 'upotato-2gvcgmdc4d6e3768',
        "data": "{\"token\":true}",
        "functionName": 'crawlerTimer',
        "delayTime": 300
      }).then((response) => {
        return response
      }).catch((error) => {
        console.error(error);
      })
    })
}